package cn.stylefeng.guns.modular.demos.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.demos.entity.AcTokenTicket;
import cn.stylefeng.guns.modular.demos.mapper.AcTokenTicketMapper;
import cn.stylefeng.guns.modular.demos.model.params.AcTokenTicketParam;
import cn.stylefeng.guns.modular.demos.model.result.AcTokenTicketResult;
import  cn.stylefeng.guns.modular.demos.service.AcTokenTicketService;
import cn.stylefeng.roses.core.mutidatasource.annotion.DataSource;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zjj
 * @since 2020-08-28
 */
@Service
public class AcTokenTicketServiceImpl extends ServiceImpl<AcTokenTicketMapper, AcTokenTicket> implements AcTokenTicketService {
	@DataSource(name="es-wx-actoken")
    @Override
    public void add(AcTokenTicketParam param){
        AcTokenTicket entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AcTokenTicketParam param){
        this.removeById(getKey(param));
    }
    @DataSource(name="es-wx-actoken")
    @Override
    public void update(AcTokenTicketParam param){
        AcTokenTicket oldEntity = getOldEntity(param);
        AcTokenTicket newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    @DataSource(name="es-wx-actoken")
    public AcTokenTicketResult findBySpec(AcTokenTicketParam param){
        List<AcTokenTicketResult> list = this.baseMapper.customList(param);
        if(list == null || list.size()<=0){
        	return null;
        }
        
        return list.get(0);
    }
    @DataSource(name="es-wx-actoken")
	@SuppressWarnings("rawtypes")
    @Override
    public List<AcTokenTicketResult> findListBySpec(AcTokenTicketParam param){
        List<AcTokenTicketResult> list = this.baseMapper.customList(param);
  
        return list;
    }
	@DataSource(name="es-wx-actoken")
    @SuppressWarnings("rawtypes")
    @Override
    public List<AcTokenTicketResult> findListBySpec2(AcTokenTicketParam param){
        List<AcTokenTicketResult> list = this.baseMapper.customList2(param);
  
        return list;
    }
	@DataSource(name="es-wx-actoken")
    @SuppressWarnings("rawtypes")
    @Override
    public List<Map<String, Object>> findMapListBySpec(AcTokenTicketParam param){
        List<Map<String, Object>> list = this.baseMapper.customMapList2(param);
  
        return list;
    }
    
	@SuppressWarnings("rawtypes")
    @Override
    public LayuiPageInfo findPageBySpec(AcTokenTicketParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }
    
    /*
    *	add by zjj
    *
    */
    @SuppressWarnings("rawtypes")
	@Override
    public Page<Map<String, Object>> findPageMapListBySpec(AcTokenTicketParam param){
        Page pageContext = getPageContext();
        return this.baseMapper.customPageMapList(pageContext, param); 
    }
    /*
    *	add by zjj
    *
    */
    @DataSource(name="es-wx-actoken")
    @Override
    public Integer customCount(AcTokenTicketParam param){
		return this.baseMapper.customCount(param);
	}

    private Serializable getKey(AcTokenTicketParam param){
        return param.getId();
    }
    
	@SuppressWarnings("rawtypes")
    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AcTokenTicket getOldEntity(AcTokenTicketParam param) {
        return this.getById(getKey(param));
    }

    private AcTokenTicket getEntity(AcTokenTicketParam param) {
        AcTokenTicket entity = new AcTokenTicket();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
